package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Comment;
import com.zretc.service.CommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: bLUeSuMMerDreamer
 * @createTime: 2020-08-30 04:07
 */
@CrossOrigin
@RequestMapping("/comment")
@Controller
public class CommentController {
    private static final Logger logger = LoggerFactory.getLogger(CommentController.class);
    @Autowired
    CommentService commentService;

    @RequestMapping("/getComments")
    @ResponseBody
    public PageInfo<Comment> getComments(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            String sellerAccount,
            String orderBy,
            Boolean desc) {
        Map<String, Object> params = new HashMap<>();
        params.put("pageNum", pageNum);
        params.put("pageSize", pageSize);
        if (sellerAccount != null && !"".equals(sellerAccount))
            params.put("sellerAccount", sellerAccount);
        if (orderBy != null && !"".equals(orderBy)) {
            params.put("orderBy", orderBy);
            if (desc != null && desc)
                params.put("desc", true);
        }
        return commentService.getComments(params);
    }


}
